<?php

class DefaultController extends FController
{
	public function actionIndex()
	{
		$this->render('index');
	}
	public function actionAdd()
	{
		$result			= array();
		// $this->layout = "ajax";
		// $this->render("item");

		if (currentUser() == false) {
			$result	= array (
				'error'		=> true,
				'message'	=> 'Please login!'
			);
		} else {
			if (!empty($_POST)) {
				$modelObject	= new Comments;
				
				
				$objectId		= $_POST['object_id'];
				$content		= nl2br($_POST['content']);
				
				$modelObject->object_id = $objectId;
				$modelObject->user_id = currentUser()->id;
				$modelObject->content = $content;
				$modelObject->created = time();
				// dump(Yii::app()->theme->baseUrl);
				if($modelObject->save()){
					$this->layout = "ajax";
					$this->render("item",array(
						'comment'=>$modelObject
					));
					exit();
					// $result	= array(
						// 'error'		=> false,
						// 'message'	=> 'This object has been updated.',
						// 'type'		=> 'like',
						// 'value'		=> 'Unlike',
						// 'people'	=> LikeString::outString(count($statistic), true),
						// 'number'=>count($statistic)
					// );
				}else{
					$result	= array(
						'error'		=> true,
						'message'	=> 'Save comment failer.',
					);
				}
				
				
				
			}
		}
		jsonOut($result);
	}
}